package com.example.xianzhi.service.impl;

import com.example.xianzhi.dao.GoodsDao;
import com.example.xianzhi.dao.impl.GoodsDaoImpl;
import com.example.xianzhi.entity.TbAdSmall;
import com.example.xianzhi.entity.TbGoods;
import com.example.xianzhi.service.GoodsService;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class GoodsServiceImpl implements GoodsService {
    private GoodsDao goodsDao = new GoodsDaoImpl();

    @Override
    public int insertGoods(TbGoods goods) {

        return goodsDao.insertGoods(goods);
    }

    @Override
    public TbGoods selectIdGoods(int goods_id) {
        return goodsDao.selectIdGoods(goods_id);
    }

    @Override
    public List<TbAdSmall> selectGoodsPic(int goods_id) {
        return goodsDao.selectGoodsPic(goods_id);
    }

    @Override
    public List<TbGoods> selectReleaseOrder(int release_id) {

        return goodsDao.selectReleaseOrder(release_id);
    }

    @Override
    public List<TbGoods> selectOrder(String goods_state, int release_id) {
        return goodsDao.selectOrder(goods_state,release_id);
    }

    @Override
    public List<TbGoods> selectGoods() {

        List<TbGoods> tbGoods = goodsDao.selectGoods();
        

        for (TbGoods tbGood : tbGoods) {
            Date release_time = tbGood.getRelease_time();

            if (release_time!=null && !release_time.equals("")){
                //转日期格式
                SimpleDateFormat data = new SimpleDateFormat("yyyy-MM-dd");
                String format = data.format(release_time);
                tbGood.setRelease_time_String(format);
            }else {
                System.out.println("时间为空！！！");
            }

        }


        return tbGoods;
    }

    @Override
    public List<TbGoods> selectGoodsinfo(String goods_name, int type_id) {
        List<TbGoods> tbGoods = goodsDao.selectGoodsinfo(goods_name,type_id);

        for (TbGoods tbGood : tbGoods) {
            Date release_time = tbGood.getRelease_time();

            //转日期格式
            SimpleDateFormat data = new SimpleDateFormat("yyyy-MM-dd");
            String format = data.format(release_time);
            tbGood.setRelease_time_String(format);

        }



        return tbGoods;
    }

    @Override
    public int deleteGoods(int goods_id) {
        return goodsDao.deleteGoods(goods_id);
    }

    @Override
    public List<TbGoods> selectIndent() {
        return goodsDao.selectIndent();
    }

    @Override
    public void delectGoods(int goods_id) {
        goodsDao.delectGoods(goods_id);
    }

    @Override
    public List<TbGoods> selectIndentClassification(String publisher, String buy_time, String addressee, int goods_id) {
        return goodsDao.selectIndentClassification(publisher,buy_time,addressee,goods_id);
    }

    @Override
    public List<TbGoods> selectGoodsByGoodsId(int goods_id) {
        return goodsDao.selectGoodsByGoodsId(goods_id);
    }

    @Override
    public void updateGoodsid(int buyer_id, Date buy_time, int goods_add_id,int goods_id) {
        goodsDao.updateGoodsid(buyer_id,buy_time,goods_add_id,goods_id);
    }

    @Override
    public List<TbGoods> selectGoodsId(String goods_name, int type_id) {
        return goodsDao.selectGoodsId(goods_name,type_id);
    }

    @Override
    public List<TbGoods> selectTypeGoods(int type_id) {
        return goodsDao.selectTypeGoods(type_id);
    }

    @Override
    public List<TbGoods> selectGoodsname(String goods_name) {
        return goodsDao.selectGoodsname(goods_name);
    }






    @Override
    public List<TbGoods> selegooodsrela(int user_id) {
        List<TbGoods> list  = goodsDao.selegooodsrela(user_id);


        return list;
    }

    @Override
    public List<TbGoods> selegooodsrhist(int user_id) {
        List<TbGoods> list  = goodsDao.selegooodsrhist(user_id);



        for (TbGoods tbGoods : list) {
            Date ddd = tbGoods.getBrowse_time();

            SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd");
            String dddStr = sdf.format(ddd);
            tbGoods.setBrowse_time_ww(dddStr);
        }


        return list;
    }

//    @Override
//    public List<TbGoods> selecttypeidgoods(int type_id) {
//
//
//        return goodsDao.selecttypeidgoods(type_id);
//    }

    @Override
    public List<TbGoods> selectusergoods() {

        return goodsDao.selectusergoods();
    }

}
